#!
#to demo the use of pipe
#usage: dir /b | sort | perl totaler.pl | more

use strict;
my ($dirs,$sizes,$total);

while(<STDIN>)
{
	chomp;
	
	if(-d $_)
	{
		$dirs++;
		print "$_\n";
		next;
	}
	$sizes += (stat($_))[7];
	$total++;
	print "$_\n";
}
print "$total files, $dirs directories.\n";
print "average file size: ",$sizes/$total,"\n";